<template>
    <div id="home">
        <el-container>
            <el-container>
                <el-aside width="300px">
                    <LeftNav  v-if="flag" :left-nav-data="leftNavData"/>
                </el-aside>
                <el-main>
                    <router-view>
                    </router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
    import {Container, Aside, Main} from "element-ui";
    import LeftNav from "@/components/leftNav/LeftNav";
    import {post} from "../../../request/AxiosMAX";
    import {UPDATE_BASE} from "../../../store/mutations-types";

    export default {
        name: "Home",
        components: {
            LeftNav,
            "el-container": Container,
            "el-aside": Aside,
            "el-main": Main,
        },
        data(){
            return{
                leftNavData:[
                ],
                flag:false
            }
        },
        created() {
            //根据基地账号id查询对应的基地
            post("/api/Studies_to_travel/base/getBaseByBaseId",{baseId:this.$store.state.user.id})
                .then(res=>{
                    if (res.code===0){
                        //更新到vuex中的用户对象中
                        this.$store.commit(UPDATE_BASE,res.data);
                        if (this.$store.state.base!=null){
                            if(this.$store.state.base.auditState===0){
                                this.leftNavData = [
                                    {
                                        name: "入住审核",
                                        icon: "el-icon-circle-plus-outline",
                                        href:"/base/base"
                                    },
                                    {
                                        name: "基地管理",
                                        icon: "el-icon-office-building",
                                        texts: [
                                            {
                                                text:"基地概况",
                                                href: "/base/baseOverview"
                                            },
                                            {
                                                text: "接待详情",
                                                href: "/base/receptionDetails"
                                            },
                                            {
                                                text: "餐饮设置",
                                                href: "/base/cateringFacilitie"
                                            },
                                            {
                                                text: "师资详情",
                                                href: "/base/teachersDetails"
                                            },
                                            {
                                                text: "研学课程",
                                                href: "/base/studiesCourse"
                                            },

                                        ]
                                    },
                                    {
                                        name: "接待计划",
                                        icon: "el-icon-pie-chart",
                                        href: "/base/ReceptionProgram"

                                    },
                                    // {
                                    //     name: "评价管理",
                                    //     icon: "el-icon-chat-line-square",
                                    //
                                    // },
                                    {
                                        name: "账户设置",
                                        icon: "el-icon-receiving",
                                        texts: [
                                            {
                                                text: "账户资料",
                                                href: "/base/accountInfo"
                                            },
                                            {
                                                text: "修改密码",
                                                href: "/base/modifyPassword"
                                            }
                                        ]
                                    }
                                ]
                            }else{
                                this.leftNavData = [
                                    {
                                        name: "入住审核",
                                        icon: "el-icon-circle-plus-outline",
                                        href:"/base/base"
                                    },
                                    {
                                        name: "账户设置",
                                        icon: "el-icon-receiving",
                                        texts: [
                                            {
                                                text: "账户资料",
                                                href: "/base/accountInfo"
                                            },
                                            {
                                                text: "修改密码",
                                                href: "/base/modifyPassword"
                                            }
                                        ]
                                    }
                                ]
                            }
                        }else {
                            this.leftNavData = [
                                {
                                    name: "入住审核",
                                    icon: "el-icon-circle-plus-outline",
                                    href:"/base/baseRegister"
                                },
                                {
                                    name: "账户设置",
                                    icon: "el-icon-receiving",
                                    texts: [
                                        {
                                            text: "账户资料",
                                            href: "/base/accountInfo"
                                        },
                                        {
                                            text: "修改密码",
                                            href: "/base/modifyPassword"
                                        }
                                    ]
                                }
                            ]

                        }
                        this.flag=true;
                        this.$router.push("/base/base");
                    }
                }).catch(err=>{
                console.info(err);
            });
        },
        beforeDestroy() {

        }
    }
</script>

<style scoped>
    #home{
        /*margin-top: 40px;*/
    }
</style>
